<template>
    <el-form ref="form" :model="form" label-width="80px">

        <el-form-item label="书名">
            <el-input v-model="form.bookName"></el-input>
        </el-form-item>
        <el-form-item label="剩余数量">
            <el-input v-model="form.bookCounts"></el-input>
        </el-form-item>
        <el-form-item label="详情">
            <el-input v-model="form.detail"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button @click="$router.replace('/body')">取消</el-button>
        </el-form-item>

    </el-form>
</template>

<script>
    import qs from 'qs'
    export default {
        name: "Insert",
        data(){
            return {
                form:{
                    bookName: '',
                    bookCounts: 0,
                    detail: '',
                }
            }
        },
        methods:{
            onSubmit(){

                const _this = this;
                axios({
                    method:"post",
                    url:"http://127.0.0.1:8088/insertBook",
                    // 默认情况下，axios将JavaScript对象序列化为JSON。 要以application / x-www-form-urlencoded格式发送数据，
                    // 方法之一：qs.stringify(),要引用
                    data: qs.stringify(this.form),
                }).then((res)=>{
                    console.log('/insert=>'+res.data);
                    _this.$router.replace("/")
                }).catch(err => {
                    console.log(err)
                })
            }
        }
    }
</script>

<style scoped>

</style>